import React, { useEffect, useState } from 'react'
import * as echarts from 'echarts';
import { Button } from "antd"
import { CloudUploadOutlined } from '@ant-design/icons';
import style from '../index.module.scss'


export default function Echarts2() {
    const [echart2, setMain] = useState('')
    const option = {
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data: ['老客户', '新客户']
        },
        series: [
            {
                name: '访问来源',
                type: 'pie',
                radius: '55%',
                center: ['50%', '60%'],
                data: [
                    { value: 200, name: '老客户' },
                    { value: 310, name: '新客户' },
                ],
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    useEffect(() => {
        var node = document.getElementById('echart2')
        setMain(node)
    }, [])
    // 基于准备好的dom，初始化echarts实例
    if (echart2 !== "") {
        var myChart = echarts.init(echart2);
        myChart.resize({ height: '400px' })
        myChart.setOption(option);
    }

    return (
        <div>
            <div className={style.pre_title}>
                <p>新老客户贷款构成</p>
                <Button className='button'><CloudUploadOutlined className="icon" />导出</Button>
            </div>
            <div id="echart2"></div>
        </div>

    )
}